package com.itboye.zhujia.me.key;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

import com.itboye.zhujia.R;
import com.itboye.zhujia.base.BaseActivity;
import com.itboye.zhujia.custom.SelectPicPopupWindow;
/**
 * 锁管理
 * @author
 *
 */
public class ActivityAdministrationKey extends BaseActivity implements OnClickListener{
	ImageView close_icon;//返回图片
	TextView add_shap_title_tv;//标题
	RelativeLayout admin_key_send;//发送钥匙
	RelativeLayout admin_key_reset;//重置钥匙
	RelativeLayout admin_key_backups;//钥匙备份
	RelativeLayout user_management;//用户管理
	RelativeLayout pass_management;//密码管理
	RelativeLayout admin_key_open;//自动开锁
	RelativeLayout admin_yao_key;//摇一摇开锁
	RelativeLayout admin_key_light;//点亮屏幕开锁
	
	TextView btn_take_photo;//期限钥匙
	TextView btn_pick_photo;//永久钥匙
	TextView btn_cancel;//取消
	
	private Dialog dialog;//自定义Dialog
	
	//自定义的弹出框类
	SelectPicPopupWindow menuWindow;
	@Override
	public int initView() {
		return 0;
	}

	@Override
	public void onMyCreate() {
		setContentView(R.layout.activity_administration_key);
		
		add_shap_title_tv.setText("锁管理");
		
		showExtraDialog();
		
	}

	@Override
	public void onClick(View v) {
		Intent intent = null;
		switch (v.getId()) {
		case R.id.close_icon://返回
			finish();
			break;
		case R.id.admin_key_send://发送钥匙
			//实例化SelectPicPopupWindow
			menuWindow = new SelectPicPopupWindow(ActivityAdministrationKey.this, itemsOnClick);
			//显示窗口
			menuWindow.showAtLocation(ActivityAdministrationKey.this.findViewById(R.id.main),
					Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置
			break;
		case R.id.admin_key_reset://重置钥匙（暂时跳转到开锁记录）
			intent=new Intent(ActivityAdministrationKey.this,ActivityUnlockingRecord.class);
			startActivity(intent);
			break;
		case R.id.admin_key_backups://钥匙备份（暂时跳转到我的钥匙）
			intent=new Intent(ActivityAdministrationKey.this,ActivityMyKey.class);
			startActivity(intent);
			break;
		case R.id.user_management://用户管理
			intent=new Intent(ActivityAdministrationKey.this,ActivityUserManagement.class);
			startActivity(intent);
			break;
		case R.id.pass_management://密码管理
			intent=new Intent(ActivityAdministrationKey.this,PassManagement.class);
			startActivity(intent);
			break;
		case R.id.admin_key_open://自动开锁(暂时弹出对话框)
			dialog.show();
			break;
		case R.id.admin_yao_key://摇一摇开锁(发送用户密码)
			intent=new Intent(ActivityAdministrationKey.this,ActivitySendPass.class);
			startActivity(intent);
			break;
		case R.id.admin_key_light://点亮屏幕开锁
			intent=new Intent();
			startActivity(intent);
			break;

		default:
			break;
		}
		
	}	
	/**
	 * 为弹出窗口实现监听类
	 */
    private OnClickListener  itemsOnClick = new OnClickListener(){

		public void onClick(View v) {
			menuWindow.dismiss();
			switch (v.getId()) {
			case R.id.btn_take_photo://期限钥匙
				break;
			case R.id.btn_pick_photo://永久钥匙
				Intent intent=new Intent(ActivityAdministrationKey.this, ActivityPermanentKey.class);
				startActivity(intent);
				break;
			case R.id.btn_cancel://取消
				break;
			default:
				break;
			}
		}
    };
    
    /**
	 * 自定义Dialog
	 */
	private void showExtraDialog() {
		dialog = new Dialog(ActivityAdministrationKey.this, R.style.rel_dialog);
		View view = LayoutInflater.from(ActivityAdministrationKey.this).inflate(R.layout.dialog_pass,
				null);
		dialog.setContentView(view);
		TextView dialog_cancel = (TextView) view.findViewById(R.id.dialog_cancel);
		TextView dialog_ok = (TextView) view.findViewById(R.id.dialog_ok);
		dialog.setCanceledOnTouchOutside(false);
		dialog_cancel.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {

				dialog.dismiss();
			}
		});
		WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();
		// 屏幕宽度
		int screenWidth = display.getWidth();
		// 屏幕高度
		int screenHeight = display.getHeight();
		Window window = dialog.getWindow();

		WindowManager.LayoutParams lp = window.getAttributes();
		window.setGravity(Gravity.CENTER);
		lp.width = screenWidth * 3 / 4;
		lp.height = LayoutParams.WRAP_CONTENT;
		window.setAttributes(lp);

	}
   
}
